home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Professional Soft Collection 1.02
/
Professional Soft Collection 1.02.iso
/
winutils
/
wingauge.zip
/
INTEGR5.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-19
|
4KB
|
115 lines
#pragma hdrfile "WinGauge.SYM"
#include <win31.h>
#include "wingauge.h"
#include "wingauge.rh"
#pragma hdrstop
#include <stdlib.h>
static void PaintBorder( HDC, short ), PaintPanel( short, HDC, short );
/*--------------------==================================--------------------*/
/* Proceed WM_DRAWITEM message -- draw owner-drawed button */
/*--------------------==================================--------------------*/
void DrawButton( LPDRAWITEMSTRUCT lpDIS, WORD wCheck )
{ register HDC hDC = lpDIS->hDC;
HPEN hPen;
SaveDC( hDC ); // Windows requires this
// Draw focus rectangle
SelectObject( hDC, GetStockObject(NULL_BRUSH) ); // Don't erase interior
hPen = SelectObject( hDC, CreatePen( PS_SOLID, 1, // Select color
(lpDIS->itemState & ODS_FOCUS ?
BLACK : LIGHTGRAY) ) );
Rectangle( hDC, 0, 0, 40, 40 ); // Draw rectangle
DeleteObject( SelectObject( hDC, hPen ) ); // Clearance
if( lpDIS->itemAction != ODA_FOCUS ) // We must draw entire button
{ short i; // State of button:
i = ( (lpDIS->itemState & ODS_SELECTED) ? 4 : // it is pushing now,
lpDIS->CtlID == wCheck ? 3 : // it is turned on,
2 ); // it is turned off.
PaintPanel( lpDIS->CtlID, hDC, i+2 ); // Draw button surface
if( i == 2 ) // Now draw border of button
PaintBorder( hDC, 2 );
else
{ hPen = SelectObject( hDC, CreatePen(PS_SOLID, 1, DARKGRAY) );
while( --i )
{ MoveTo(hDC,i+2,36); LineTo(hDC,i+2,i+2); LineTo(hDC,36,i+2); }
DeleteObject( SelectObject( hDC, hPen ) );
}
Rectangle( hDC, 2, 2, 38, 38 );
}
RestoreDC( hDC, -1 ); // Restore old (last saved) DC
}
/*--------------------==================================--------------------*/
/* Draw "turned off" 3-D button border */
/*--------------------==================================--------------------*/
static void PaintBorder( HDC hDC, short sOffset )
{ register short s1 = sOffset + 1, // For optimization
s34 = sOffset + 34; // and simplification
HPEN hPen;
hPen = SelectObject( hDC, CreatePen(PS_SOLID, 1, DARKGRAY) );
MoveTo( hDC, s34, s1 ); LineTo( hDC, s34, s34 ); LineTo( hDC, s1, s34 );
DeleteObject( SelectObject( hDC, GetStockObject(WHITE_PEN) ) );
MoveTo( hDC, s1, s34 ); LineTo( hDC, s1, s1 ); LineTo( hDC, s34, s1 );
SelectObject( hDC, hPen );
}
/*--------------------==================================--------------------*/
/* Draw interior of gauge */
/*--------------------==================================--------------------*/
static void PaintPanel( short sPanel, HDC hDC, short sOffset )
{ HDC hMemDC;
char cBuffer[6];
hMemDC = CreateCompatibleDC( hDC ); // Draw button bitmap
SelectObject( hMemDC, ahBitmaps[sPanel] );
BitBlt( hDC, sOffset, sOffset, 32, 32, hMemDC, 0, 0, SRCCOPY );
DeleteDC( hMemDC );
lstrcat( itoa( awNew[sPanel], cBuffer, 10 ), "%" ); // Prepare text
(*afnPaint[sPanel])( hDC, sOffset, awNew[sPanel], cBuffer ); // Fill bitmap
SetTextAlign( hDC, TA_CENTER ); // Prepare DC
SetBkMode( hDC, TRANSPARENT );
TextOut( hDC, sOffset+15, sOffset-2,
cBuffer, lstrlen( cBuffer ) ); // Draw text
}
/*--------------------==================================--------------------*/
/* Draw working gauge or integrating icon as an icon */
/*--------------------==================================--------------------*/
void PaintIcon( HWND hWnd, short sPanel )
{ HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint( hWnd, &ps );
SelectObject( hDC, GetStockObject(NULL_BRUSH) ); // Do not erase
Rectangle( hDC, 0, 0, 36, 36 ); // rectangle interior
PaintBorder( hDC, 0 ); // Draw 3-D border
if( sPanel == 0 ) // Draw only icon
{ HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE(1) );
DrawIcon( hDC, 2, 2, hIcon );
FreeResource( hIcon );
}
else // Draw panel
PaintPanel( sPanel, hDC, 2 );
EndPaint( hWnd, &ps );
}